<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="Guillaume Laborde - Guillaume Lameyre" />
<link rel="stylesheet" media="screen" type="text/css" title="style" href="css/style.css" />
<title>ContactBook</title>
</head>

<body>

	<c:set var="account" value="${sessionScope.account}" />
	<c:set var="groups" value="${requestScope.groups}" />
	<c:set var="contactsWithoutGroup" value="${requestScope.contactsWithoutGroup}" />
	<c:set var="nbContacts" value="${requestScope.nbContacts}" />
	
	<c:if test="${empty account}">
		<c:redirect url="Index" />
	</c:if>
	
	<div id="mainframe">
		<c:import url="include/privateBanner.html" />
		<h1>Gestion des contacts</h1>
		<div id="content">
			
			<form action="AddContact" method="POST" class="right">
				<input type="image" src="images/contact_add.png" alt="Ajouter un contact" title="Cliquer ici pour ajouter un contact" />
			</form>
			
			<c:if test="${nbContacts == '0'}" >
				<p class="warning">Vous n'avez aucun contact dans votre ContactBook.</p>
				<p>Pour créer votre premier contact, cliquez sur "Ajouter un contact".</p>
			</c:if>
			
           	<c:forEach var="group" items="${groups}">
           		<c:if test="${not empty group.contacts}" >
           			<jsp:useBean id="group" class="contactbook.model.Group" scope="page" />
            		<fieldset>
            			<legend><img src="images/group.png" alt="" /><jsp:getProperty name="group" property="name" /></legend>
            			<table class="border">
	                        <c:forEach var="contact" items="${group.contacts}">
	                        	<jsp:useBean id="contact" class="contactbook.model.Contact" scope="page" />
	            				<tr>
	            					<form action="InfoContact" method="POST">
	            						<td width="20px"><input type="image" src="images/contact_go.png" alt="Voir" title="Voir le contact" /></td>
	            						<td><input type="image" src="" alt="<jsp:getProperty name="contact" property="firstName" /> <jsp:getProperty name="contact" property="lastName" />" title="Voir le contact" /></td>
	            						<input type="hidden" name="contactId" value="<jsp:getProperty name="contact" property="id" />" />
	            					</form>
	            					<td width="40px">
	            						<form action="UpdateContact" method="POST" class="inline">
			            					<input type="image" src="images/contact_edit.png" alt="Modifier" title="Modifier" />
			            					<input type="hidden" name="contactId" value="<jsp:getProperty name="contact" property="id" />" />
			            				</form>
			            				<form action="DeleteContact" method="POST" class="inline">
			            					<input type="image" src="images/contact_delete.png" alt="Supprimer" title="Supprimer" />
				                       		<input type="hidden" name="contactId" value="<jsp:getProperty name="contact" property="id" />" />
				                       	</form>
									</td>
								</tr>
	                        </c:forEach>
                        </table>
            		</fieldset>
            	</c:if>
           	</c:forEach>

			<c:if test="${not empty contactsWithoutGroup}">
				<fieldset>
            		<legend><img src="images/no_group.png" alt="" /> Groupe par défaut</legend>
            		<table class="border">
	            		<c:forEach var="contactWithoutGroup" items="${contactsWithoutGroup}">
	            			<jsp:useBean id="contactWithoutGroup" class="contactbook.model.Contact" scope="page" />
	            			<tr>
	            				<form action="InfoContact" method="POST">
            						<td width="20px"><input type="image" src="images/contact_go.png" alt="Voir" title="Voir le contact" /></td>
            						<td><input type="image" src="" alt="<jsp:getProperty name="contactWithoutGroup" property="firstName" /> <jsp:getProperty name="contactWithoutGroup" property="lastName" />" title="Voir le contact" /></td>
            						<input type="hidden" name="contactId" value="<jsp:getProperty name="contactWithoutGroup" property="id" />" />
            					</form>
            					<td width="40px">
            						<form action="UpdateContact" method="POST" class="inline">
		            					<input type="image" src="images/contact_edit.png" alt="Modifier" title="Modifier" />
		            					<input type="hidden" name="contactId" value="<jsp:getProperty name="contactWithoutGroup" property="id" />" />
		            				</form>
		            				<form action="DeleteContact" method="POST" class="inline">
			            				<input type="image" src="images/contact_delete.png" alt="Supprimer" title="Supprimer" />
				                       	<input type="hidden" name="contactId" value="<jsp:getProperty name="contactWithoutGroup" property="id" />" />
									</form>
								</td>
							</tr>
	            		</c:forEach>
	            		</table>
            	</fieldset>
           	</c:if>
		</div>
		<c:import url="include/bottom.html" />
	</div>

</body>
</html>